keyVars = c("Residence", "Gender", "Education_level", "Labor_status"),
weightVar = c("Weight"),
sensibleVar = c("Health"),
alpha = 0)
sdcInitial@risk
risk <- sdcInitial@risk$individual
dados2 <- cbind(dados, risk)
dados2$kAnon <- dados2$fk + 1
print(sdcInitial, 'kAnon')
sum(sdcInitial@risk$individual[,2] < 5)
sdcInitial <- ldiversity(obj = sdcInitial, ldiv_index = c("Health"), missing = NA)
sdcInitial@risk$ldiversity
sdcInitial@risk$ldiversity[,'Health_Distinct_Ldiversity']
ldive <- sdcInitial@risk$ldiversity[,'Health_Distinct_Ldiversity']
dados3 <- cbind(dados2, ldive)
sdcInitial <- createSdcObj(dat  = dados,
keyVars = c("Labor_status", "Residence", "Gender", "Education_level"),
weightVar = c("Weight"),
sensibleVar = c("Health"),
alpha = 0)
sdcInitial@risk
risk <- sdcInitial@risk$individual
dados2 <- cbind(dados, risk)
dados2$kAnon <- dados2$fk + 1
print(sdcInitial, 'kAnon')
sum(sdcInitial@risk$individual[,2] < 5)
sdcInitial <- ldiversity(obj = sdcInitial, ldiv_index = c("Health"), missing = NA)
sdcInitial@risk$ldiversity
sdcInitial@risk$ldiversity[,'Health_Distinct_Ldiversity']
ldive <- sdcInitial@risk$ldiversity[,'Health_Distinct_Ldiversity']
library(sdcMicro)
No <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Residence <- c("Urban", "Urban", "Urban", "Urban", "Rural", "Urban", "Urban", "Urban", "Urban", "Urban")
Gender <- c("Female", "Female", "Female", "Male", "Female", "Male", "Female", "Male", "Female", "Female")
Education_level <- c("Secondary incomplete", "Secondary incomplete", "Primary incomplete", "Secondary complete", "Secondary complete", "Secondary complete", "Primary complete", "Post-secondary", "Secondary incomplete", "Secondary incomplete")
Labor_status <- c("Employed", "Employed", "Non-LF", "Employed", "Unemployed", "Employed", "Non-LF", "Unemployed", "Non-LF", "Non-LF")
Health <- c("yes", "yes", "yes", "yes", "yes", "no", "no", "yes", "no", "yes")
Weight <- c(180, 180, 215, 76, 186, 76, 180, 215, 186, 76)
# fk <- c(2, 2, 1, 2, 1, 2, 1, 1, 2, 2)
# Fk <- c(360, 360, 215, 152, 186, 152, 180, 215, 262, 262)
# risk <- c(0.0054, 0.0054, 0.0251, 0.0126, 0.0282, 0.0126, 0.0290, 0.0251, 0.0074, 0.0074)
dados <- data.frame(No, Residence, Gender, Education_level, Labor_status, Health, Weight)
selectedSensibleVar = c("Health")
sdcInitial <- createSdcObj(dat  = dados,
keyVars = c("Residence", "Gender", "Education_level", "Labor_status"),
weightVar = c("Weight"),
sensibleVar = c("Health"),
alpha = 0)
sdcInitial@risk
risk <- sdcInitial@risk$individual
dados2 <- cbind(dados, risk)
dados2$kAnon <- dados2$fk + 1
print(sdcInitial, 'kAnon')
sum(sdcInitial@risk$individual[,2] < 5)
sdcInitial <- ldiversity(obj = sdcInitial, ldiv_index = c("Health"))
sdcInitial@risk$ldiversity
sdcInitial@risk$ldiversity[,'Health_Distinct_Ldiversity']
ldive <- sdcInitial@risk$ldiversity[,'Health_Distinct_Ldiversity']
dados3 <- cbind(dados2, ldive)
View(sdcInitial)
View(dados)
library(sdcMicro)
No <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Residence <- c("Urban", "Urban", "Urban", "Urban", "Rural", "Urban", "Urban", "Urban", "Urban", "Urban")
Gender <- c("Female", "Female", "Female", "Male", "Female", "Male", "Female", "Male", "Female", "Female")
Education_level <- c("Secondary incomplete", "Secondary incomplete", "Primary incomplete", "Secondary complete", "Secondary complete", "Secondary complete", "Primary complete", "Post-secondary", "Secondary incomplete", "Secondary incomplete")
Labor_status <- c("Employed", "Employed", "Non-LF", "Employed", "Unemployed", "Employed", "Non-LF", "Unemployed", "Non-LF", "Non-LF")
Health <- c("yes", "yes", "yes", "yes", "yes", "no", "no", "yes", "no", "yes")
Weight <- c(180, 180, 215, 76, 186, 76, 180, 215, 186, 76)
# fk <- c(2, 2, 1, 2, 1, 2, 1, 1, 2, 2)
# Fk <- c(360, 360, 215, 152, 186, 152, 180, 215, 262, 262)
# risk <- c(0.0054, 0.0054, 0.0251, 0.0126, 0.0282, 0.0126, 0.0290, 0.0251, 0.0074, 0.0074)
dados <- data.frame(No, Residence, Gender, Education_level, Labor_status, Health, Weight)
sdcInitial <- createSdcObj(dat  = dados,
keyVars = c("Residence", "Gender", "Education_level", "Labor_status"),
weightVar = c("Weight"),
sensibleVar = c("Health"),
alpha = 0)
sdcInitial@risk
risk <- sdcInitial@risk$individual
dados2 <- cbind(dados, risk)
dados2$kAnon <- dados2$fk + 1
print(sdcInitial, 'kAnon')
sum(sdcInitial@risk$individual[,2] < 5)
sdcInitial <- ldiversity(obj = sdcInitial, ldiv_index = c("Health"))
sdcInitial@risk$ldiversity
nome <- c("Mayra", "Fabio")
idade <- c(31, 36)
dados <- data.frame(nome, idade)
View(dados)
library(xlsx)
readxl::read_xlsx("C:/Users/mpizzott/Desktop/Pasta1.xlsx")
dados <- readxl::read_xlsx("C:/Users/mpizzott/Desktop/Pasta1.xlsx")
View(dados)
str(dados)
dados <- readxl::read_xlsx("C:/Users/mpizzott/Desktop/Pasta1.xlsx")
str(dados)
View(dados)
head(dados[,5])
dados[,5]
dados[5,]
# ******************************************************************************
# *** Pesquisa TIC Educação 2022 - Alunos
# *** Processamento Tabelas
# *** Programador(a): João Claudio
# *** Última atualização: 27/07/2023
# ******************************************************************************
cat("\014") # Limpa console R
rm(list = ls()) # Limpa environment
# Carrega (e instala, se necessário) pacotes requeridos
if (!require("install.load")) install.packages("install.load")
install.load::install_load("haven", "tidyverse", "survey", "openxlsx")
# Define diretório dos dicionários
setwd("Z:/CETIC.BR (repositório)/Pesquisas/TIC EDUCAÇÃO/2022/Processamento/Tabelas/Alunos")
# Lê os dicionários de indicadores e agrupamentos
dic_indicadores <- list.files()[grepl('indicadores', list.files())]
dic_indicadores <- read.csv2(dic_indicadores, encoding = "UTF-8")
dic_agrupamentos <- list.files()[grepl('agrupamentos', list.files())]
dic_agrupamentos <- read.csv2(dic_agrupamentos, encoding = "UTF-8")
# Seleciona todas as variáveis que serão utilizadas nas tabelas
agrupamentos <- data.frame(var = dic_agrupamentos$co_pergunta)
indicadores <- data.frame(var = dic_indicadores$co_pergunta)
filtros <- data.frame(var = dic_indicadores$tx_filtro)
rm(dic_indicadores, dic_agrupamentos)
filtros <- filtros %>% mutate(var = gsub(pattern = "=.*", replacement = "",
gsub(pattern = " =.*", replacement = "", var)))
filtros <- filtros %>% filter(var != "TOTAL")
vars_dics <- rbind(agrupamentos, filtros, indicadores)
vars_dics <- distinct(vars_dics)
rm(agrupamentos, indicadores, filtros)
# Define diretório da base de dados
setwd("Z:/CETIC.BR (repositório)/Pesquisas/TIC EDUCAÇÃO/2022/Processamento/Microdados/Base final")
# Leitura do banco de dados de alunos
dados <- read_sav("Job1706-TIC_Educacao_alunos.sav") %>%
select(-c(PESO, UPA,ESTRATO))
# Define diretório dos pesos
setwd("Z:/CETIC.BR (repositório)/Pesquisas/TIC EDUCAÇÃO/2022/Processamento/Microdados/PesosBases")
# Leitura do banco de dados com o peso dos alunos
pesos <- read_sav("Alunos_Pesos_Calibrados.sav")%>%
select(ID_QUEST,PESO_ALUNO_FINAL, peso_aluno_calibrado, estrato_amostra,CO_ENTIDADE) %>%
rename(PESO = peso_aluno_calibrado,
ESTRATO=estrato_amostra,
UPA = CO_ENTIDADE)
sum(pesos$PESO)
table(pesos$ESTRATO, exclude = NULL)
str(pesos$ESTRATO)
pesos$ESTRATO = as.numeric(as.factor(pesos$ESTRATO))
table(pesos$ESTRATO)
str(pesos$ESTRATO)
#Adicionando o peso e o estrato ao banco
dados <- left_join(dados, pesos, by = "ID_QUEST")
sum(dados$PESO)
# Verifica quais variáveis precisam ser criadas
vars_dados <- data.frame(var = names(dados))
vars_faltantes <- vars_dics$var[!(vars_dics$var %in% vars_dados$var)]
cat(vars_faltantes)
# cria a variável Localização
universo <- read_sav("Z:/CETIC.BR (repositório)/Pesquisas/TIC EDUCAÇÃO/2022/Planejamento/desenho amostral/BaseUniverso/universo.sav")
universo <- universo %>% select(c(CO_ENTIDADE, TP_LOCALIZACAO, QT_MAT_BAS,
IN_INF_CRE, IN_INF_PRE, IN_FUND_AI,
IN_FUND_AF, IN_MED, IN_PROF,
IN_PROF_TEC)) %>%
rename(ID_ESCOLA_CENSO = CO_ENTIDADE,
COD_ZONA = TP_LOCALIZACAO, # Agrupamento ÁREA
TOTALMATRICULAS = QT_MAT_BAS)
# universo <- universo %>% select(c(CO_ENTIDADE, TP_LOCALIZACAO, QT_MAT_BAS,
#                                   IN_INF_CRE, IN_INF_PRE, IN_FUND_AI,
#                                   IN_FUND_AF, IN_EJA_FUND, IN_MED, IN_PROF,
#                                   IN_PROF_TEC, IN_EJA_MED,
#                                   QT_TUR_INF_CRE, QT_TUR_INF_PRE, QT_TUR_FUND_AI,
#                                   QT_TUR_FUND_AF, QT_TUR_EJA_FUND, QT_TUR_MED, QT_TUR_PROF,
#                                   QT_TUR_PROF_TEC, QT_TUR_EJA_MED,
#                                   QT_MAT_INF_CRE, QT_MAT_INF_PRE, QT_MAT_FUND_AI,
#                                   QT_MAT_FUND_AF, QT_MAT_EJA_FUND, QT_MAT_MED, QT_MAT_PROF,
#                                   QT_MAT_PROF_TEC,  QT_MAT_EJA_MED,
#                                   QT_DOC_INF_CRE, QT_DOC_INF_PRE, QT_DOC_FUND_AI,
#                                   QT_DOC_FUND_AF, QT_DOC_EJA_FUND, QT_DOC_MED, QT_DOC_PROF,
#                                   QT_DOC_PROF_TEC, QT_DOC_EJA_MED)) %>%
#                           rename(ID_ESCOLA_CENSO = CO_ENTIDADE,
#                                  COD_ZONA = TP_LOCALIZACAO, # Agrupamento ÁREA
#                                  TOTALMATRICULAS = QT_MAT_BAS)
dados <- left_join(dados, universo, by = "ID_ESCOLA_CENSO")
rm(universo)
table(dados$TOTALMATRICULAS, exclude = NULL)
#####
#Extraindo váriaveis referentes as escolas
escolas <- read_sav("Z:/CETIC.BR (repositório)/Pesquisas/TIC EDUCAÇÃO/2022/Processamento/Microdados/Base final/Job1706-TIC_Educacao_gestores.sav")
escolas <-  escolas %>% select(c(ID_ESCOLA_CENSO, P26_A, P26_B, P26_C, P26_D,
P26_E, P26_F, P26_G, P13_A, P13_B, P13_C))
# escolas <-  escolas %>% select(c(ID_ESCOLA_CENSO, P26_A, P26_B, P26_C, P26_D,
#                                  P26_E, P26_F, P26_G, P13_A, P13_B, P13_C,
#                                  P60_D, P62_2_E, P62_2_F, P62_2_G,
#                                  P63_2_E, P63_2_F, P63_2_G,
#                                  S04_L, S04_M, S04_N, S04_O, S04_P))
#============================================================
# Testando sobreposição de variáveis em alunos e escolas
var_comuns <-  names(escolas)[names(escolas) %in% names(dados)]
var_comuns
#============================================================
# Adicionando variáveis referentes as escolas
dados <- left_join(dados,escolas,
by = "ID_ESCOLA_CENSO")
table(dados$P26_A, exclude = NULL)
sum(is.na(dados$P26_A))
# Criação de variáveis de agrupamento/ agregadas
dados <- dados %>% mutate(
# Retirando NA nas variáveis que não temos informação de escolas
P26_A	=  ifelse(is.na(P26_A), 98, P26_A), # 98- Não respondeu
P26_B	=  ifelse(is.na(P26_B), 98, P26_B),# 98- Não respondeu
P26_C	=  ifelse(is.na(P26_C), 98, P26_C),	# 98- Não respondeu
P26_D	=  ifelse(is.na(P26_D), 98, P26_D),	# 98- Não respondeu
P26_E	=  ifelse(is.na(P26_E), 98, P26_E),	# 98- Não respondeu
P26_F	=  ifelse(is.na(P26_F), 98, P26_F),	# 98- Não respondeu
P26_G	=  ifelse(is.na(P26_G), 98, P26_G),# 98- Não respondeu
P13_A	=  ifelse(is.na(P13_A), 999998, P13_A),	# 98- Não respondeu
P13_B	=  ifelse(is.na(P13_B), 999998, P13_B),	# 98- Não respondeu
P13_C	=  ifelse(is.na(P13_C), 999998, P13_C),# 98- Não respondeu
A_TOTAL = 1,
P2_FX = case_when(P2>= 9 & P2<=10 ~ 1, # 1 - De 9 a 10 anos
P2>= 11 & P2<=12 ~ 2,# 2 - De 11 a 12 anos
P2>= 13 & P2<=14 ~ 3,# 3 - De 13 a 14 anos
P2>= 15 & P2<=17 ~ 4,# 4 - De 15 a 17 anos
P2>= 18 & P2< 999999998 ~ 5, # 5 - De 19 anos ou mais
P2 == 999999998 ~ 98), # Não Respondeu
CAP =as.character(dados$ESTRATO_ERRO) %>% substring(2,2),
COD_TIPO_CIDADE =  case_when(CAP==1 ~1, T ~2), # 1 - capital 2 - interior
### No banco COD_DEPENDENCIA é categorizada como a seguir:
# 1 = "Municipal"
# 2 = "Estadual"
# 3 = "Particular"
# 4 = "Federal"
COD_DEPENDENCIA_2_1_1 = case_when(COD_DEPENDENCIA==1 ~ 0, # 0 - Municipal
COD_DEPENDENCIA==2 ~ 1, # 1 - Estadual
TRUE ~ 99),
COD_DEPENDENCIA_2_2_1 = ifelse(dados$COD_DEPENDENCIA!=3 ,3 ,99), # 3 - Escolas públicas
COD_DEPENDENCIA_2_3_1 = ifelse(dados$COD_DEPENDENCIA==3 , 2 ,99), # 2-Escolas particulares recebem  - restante recebe 99
NIVEL_ENSINO  = case_when((IN_INF_CRE == 1 | IN_INF_PRE == 1 | IN_FUND_AI == 1) & IN_FUND_AF == 0 &	IN_MED == 0 &	IN_PROF == 0 & IN_PROF_TEC == 0 ~ 1, # Até Educação Infantil ou anos iniciais do Ensino Fundamental
IN_FUND_AF == 1 &	IN_MED == 0 &	IN_PROF == 0 & IN_PROF_TEC == 0 ~ 2, # Até anos finais do Ensino Fundamental
IN_MED == 1 |	IN_PROF == 1 | IN_PROF_TEC == 1 ~ 3, TRUE ~ 0),# Até Ensino Médio ou Educação Profissional
PORTE = case_when(TOTALMATRICULAS <= 50 ~ 1, # Até 50 matrículas
TOTALMATRICULAS >= 51 & TOTALMATRICULAS <= 150 ~ 2,
TOTALMATRICULAS >= 151 & TOTALMATRICULAS <= 300 ~ 3,
TOTALMATRICULAS >= 301 & TOTALMATRICULAS <= 500 ~ 4,
TOTALMATRICULAS >= 501 & TOTALMATRICULAS <= 1000 ~ 5,
TOTALMATRICULAS >= 1001 ~ 6, TRUE ~ 99),
P26_AGREG = case_when(P26_A == 1 | P26_B == 1 | P26_C == 1 | P26_D == 1 |
P26_E == 1 | P26_F == 1 | P26_G == 1 ~ 1,
P26_A == 98 ~ 98, TRUE ~ 0), # 0 - Não 1 - Sim 98 -Não respondeu
P13_AGREG =case_when((P13_A > 0 & P13_A < 999998) |
(P13_B > 0 & P13_B < 999998) |
(P13_C > 0 & P13_C < 999998) ~ 1,
P13_A==999998 ~ 98 ,
TRUE ~ 0), # 0 - Não 1 - Sim
P26_P13_AGREG = case_when(P26_AGREG == 1 & P13_AGREG == 1 ~ 1,
P26_AGREG == 98 ~ 98, TRUE ~ 0), # 0 - Não 1 - Sim
#Domicílio com Acesso a internet
P5A_2_AGREG = ifelse(P5A_2==1,1,0), # 1- sim , 0 - Não
#Presença de computador no domicílio
P6_AGREG = case_when(P6_A==1 | P6_B == 1 | P6_C == 1 ~ 1, TRUE ~ 0 ),
#DOMICÍLIO COM ACESSO À INTERNET E COMPUTADOR
P5A_P6_AGREG = ifelse(P5A_2_AGREG==1 & P6_AGREG == 1, 1,0),
#ACESSO À INTERNET PELO CELULAR DE FORMA EXCLUSIVA
P11_C2_EXCLUSIVO = ifelse(P11_A2 != 1 & P11_B2 != 1 & P11_C2 == 1 &
P11_D2 != 1 &
P11_E2 != 1 & P11_F2 != 1,1,0),
#Arrumar
P11_DISPOSITIVOS = case_when((P11_A2 == 1 | P11_B2 == 1 | P11_F2 == 1)
& P11_C2 !=1 & P11_D2 != 1 & P11_E2 != 1 ~ 1, # 1-Acesso exclusivo por computador
(P11_A2 !=1 & P11_B2 !=1 & P11_F2 !=1) &
P11_D2 != 1 & P11_E2 != 1 & P11_C2 == 1  ~ 2 ,# 2- Acesso exclusivo por Celular
(P11_A2 == 1 | P11_B2 == 1 | P11_F2 == 1)
& P11_C2 == 1  ~ 3, # Acesso por computador e Celular
TRUE ~ 99 ),#
#Escola com ACESSO À INTERNET
P8_P11_AGREG = ifelse(P8_A2==1 | (P11_A2 == 1 | P11_B2 == 1 | P11_C2 == 1 |
P11_D2 == 1 |
P11_E2 == 1 | P11_F2 == 1),1,0),
#ALUNOS QUE ACESSAM A INTERNET NA ESCOLA
P18_P19_P21_AGREG = case_when(P18_A2 == 1 | P18_B == 1 | P18_C == 1 |
P18_D == 1 |P18_OUTROS ==1 | P19_A2==1| P19_B==1|
P19_C == 1 |P21==1 ~ 1, # Sim
TRUE  ~ 0),
P7_AGREG = case_when(P7_A == 1 | P7_B == 1 | P7_C == 1  ~ 1, # Sim
TRUE ~ 0),
#O Aluno recebeu algum aparelho do governo?
P12_AGREG = case_when(P12_A == 1 | P12_B == 1 | P12_C == 1 | P12_D == 1~1,
TRUE ~ 0),
#Conexão no celular
P14_AGREG = case_when(P14_A == 1 & P14_B!=1 ~ 1, # 1 WiFi
P14_A !=1 & P14_B==1 ~ 2, # 2 -3G ou 4G
P14_A == 1 & P14_B==1 ~ 3, # Ambos
TRUE ~ 99),
#Conexão no celular na escola
P20_AGREG  = case_when(P20_A == 1 & P20_B!=1 ~ 1,
P20_A !=1 & P20_B==1 ~ 2,
P20_A == 1 & P20_B==1 ~ 3,
TRUE ~ 99),
# Alunos que usam redes sociais
P24_AGREG = ifelse(P24_A2 == 1 | P24_B2 == 1 | P24_C2 == 1 |
P24_D2 == 1 |P24_E2 ==1 | P24_G==1| P24_H==1|
P24_I == 1 |P24_J==1 | P24_K==1| P24_L==1|P24_OUTROS2==1,1,0),
#ALUNOS QUE RECEBERAM ORIENTAÇÃO E APOIO DOS PROFESSORES PARA USO DAS TECNOLOGIAS DIGITAIS
P29_30_AGREG = ifelse(P29_A == 1 | P29_B == 1 | P29_C == 1 |
P29_D == 1 |P29_E ==1 | P30_A==1| P30_B==1|
P30_C == 1 |P30_D==1 | P30_E==1,1,0)
)
# teste <- dados %>% select(ID_QUEST, ID_ESCOLA_CENSO, contains("MED"),
#                           P60_D, P62_2_E, P62_2_F, P62_2_G,
#                           P63_2_E, P63_2_F, P63_2_G,
#                           S04_L, S04_M, S04_N, S04_O, S04_P,
#                           NIVEL_ENSINO, SERIE_2, TURMA_2) %>%
#                    filter(NIVEL_ENSINO == 2 & SERIE_2 == 3)
# setwd("Z:/CETIC.BR (repositório)/Pesquisas/TIC EDUCAÇÃO/2022/Processamento/Tabelas/Alunos")
# writexl::write_xlsx(teste, "Alunos_EnsinoMédio.xlsx")
#===============================================================================
#Verifica se todas as váriaveis foram criadas
vars_dados <- data.frame(var = names(dados))
vars_faltantes <- vars_dics$var[!(vars_dics$var %in% vars_dados$var)]
cat(vars_faltantes)
# Remoção das variáveis STRING
strings <- dados %>%  select_if(is.character) %>% names() # identificando as variáveis de caracteres
# dados <- dados %>% select(-c(strings)) # retirando as variaveis de caracteres
dados <- dados %>% select_if(~!is.character(.))
# Salva os dados (em .csv)
setwd("Z:/CETIC.BR (repositório)/Pesquisas/TIC EDUCAÇÃO/2022/Processamento/Tabelas/Alunos")
write.csv2(dados, "tic_educacao_2022_alunos_dados.csv", row.names = FALSE)
write.csv2(dados, "./Inglês/ict_in_education_2022_students_dados.csv", row.names = FALSE)
write.csv2(dados, "./Espanhol/tic_educacion_2022_alumnos_dados.csv", row.names = FALSE)
write_sav(dados, "tic_educacao_2022_alunos_dados.sav")
cat("\014") # Limpa console R
rm(list = ls()) # Limpa área de trabalho
# Ctrl+shift+F10 - restart your R session
encoding <- "UTF8"
options(encoding = encoding)
options(tz = "America/Sao_Paulo")
#Rtools
# Instalação do pacote tabular
remove.packages("tabular")
setwd("Z:/CETIC.BR (repositório)/Base de conhecimento/DesenvolvimentoTabelas/tabular")
install.packages("tabular_0.0.1.8.tar.gz", repos = NULL, type = "source")
library(tabular)
# Diretório dos dicionários e tabelas
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
# Lista todos os arquivos .csv
files <- list.files(pattern = 'csv')
files
# Seleciona cada um dos parâmetros a partir da palavra chave
indicadores <- files[grepl('indicadores', files)]
agrupamentos <- files[grepl('agrupamentos', files)]
perguntas <- files[grepl('perguntas', files)]
respostas <- files[grepl('respostas', files)]
dados <- files[grepl('dados', files)]
pesquisa <- strsplit(indicadores, "_dicionario")[[1]][1]
# Processamento Tabelas
TABELAS <- tabular::Rodar(arq_indicadores = indicadores,
arq_agrupamentos = agrupamentos,
arq_perguntas = perguntas,
arq_respostas = respostas,
dados = dados)
# Exporta tabelas
TABELAS$prop <- tabular::ExportarTabela(TABELAS, type = "prop", idioma = "pt")
TABELAS$erro <- tabular::ExportarTabela(TABELAS, type = "erro", idioma = "pt")
TABELAS$total <- tabular::ExportarTabela(TABELAS, type = "total", idioma = "pt")
TABELAS$errototal <- tabular::ExportarTabela(TABELAS, type = "errototal", idioma = "pt")
# Salva tabelas no diretório
openxlsx::saveWorkbook(wb = TABELAS$prop,
file = paste0(pesquisa, "_tabela_proporcao_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$erro,
file = paste0(pesquisa, "_tabela_margem_de_erro_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$total,
file = paste0(pesquisa, "_tabela_total_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$errototal,
file = paste0(pesquisa, "_tabela_margem_de_erro_total_v1.0.xlsx"),
overwrite = TRUE)
# Verifica o scale utilizado
# Domicílios 2020: scale=0.00642244440548866
# Indivíduos 2020: scale=0.00686237914069572
# Ondas Painel: scale=0.00684006541327602
# Painel Onda 5: scale=0.00684008296372294
# Cultura 2022: scale =0.00545711704814438
# Saúde 2022 Gestores: scale =0.0079664308705664
# Saúde 2022 Médicos: scale =0.0100030602022529
# Saúde 2022 Enfermeiros: scale =0.00879658739063795
# Painel Onda 6: scale = 0.00562035721138633
TABELAS$design$scale
TABELAS$design$combined.weights
TABELAS$design$type
cat("\014") # Limpa console R
rm(list = ls()) # Limpa área de trabalho
# Ctrl+shift+F10 - restart your R session
encoding <- "UTF8"
options(encoding = encoding)
options(tz = "America/Sao_Paulo")
#Rtools
# Instalação do pacote tabular
remove.packages("tabular")
setwd("Z:/CETIC.BR (repositório)/Base de conhecimento/DesenvolvimentoTabelas/tabular")
install.packages("tabular_0.0.1.8.tar.gz", repos = NULL, type = "source")
library(tabular)
# Diretório dos dicionários e tabelas
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
# Lista todos os arquivos .csv
files <- list.files(pattern = 'csv')
files
# Seleciona cada um dos parâmetros a partir da palavra chave
indicadores <- files[grepl('indicadores', files)]
agrupamentos <- files[grepl('agrupamentos', files)]
perguntas <- files[grepl('perguntas', files)]
respostas <- files[grepl('respostas', files)]
dados <- files[grepl('dados', files)]
pesquisa <- strsplit(indicadores, "_dicionario")[[1]][1]
# Processamento Tabelas
TABELAS <- tabular::Rodar(arq_indicadores = indicadores,
arq_agrupamentos = agrupamentos,
arq_perguntas = perguntas,
arq_respostas = respostas,
dados = dados)
# Exporta tabelas
TABELAS$prop <- tabular::ExportarTabela(TABELAS, type = "prop", idioma = "pt")
TABELAS$erro <- tabular::ExportarTabela(TABELAS, type = "erro", idioma = "pt")
TABELAS$total <- tabular::ExportarTabela(TABELAS, type = "total", idioma = "pt")
TABELAS$errototal <- tabular::ExportarTabela(TABELAS, type = "errototal", idioma = "pt")
# Salva tabelas no diretório
openxlsx::saveWorkbook(wb = TABELAS$prop,
file = paste0(pesquisa, "_tabela_proporcao_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$erro,
file = paste0(pesquisa, "_tabela_margem_de_erro_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$total,
file = paste0(pesquisa, "_tabela_total_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$errototal,
file = paste0(pesquisa, "_tabela_margem_de_erro_total_v1.0.xlsx"),
overwrite = TRUE)
# Verifica o scale utilizado
# Domicílios 2020: scale=0.00642244440548866
# Indivíduos 2020: scale=0.00686237914069572
# Ondas Painel: scale=0.00684006541327602
# Painel Onda 5: scale=0.00684008296372294
# Cultura 2022: scale =0.00545711704814438
# Saúde 2022 Gestores: scale =0.0079664308705664
# Saúde 2022 Médicos: scale =0.0100030602022529
# Saúde 2022 Enfermeiros: scale =0.00879658739063795
# Painel Onda 6: scale = 0.00562035721138633
TABELAS$design$scale
TABELAS$design$combined.weights
TABELAS$design$type
cat("\014") # Limpa console R
rm(list = ls()) # Limpa área de trabalho
# Ctrl+shift+F10 - restart your R session
encoding <- "UTF8"
options(encoding = encoding)
options(tz = "America/Sao_Paulo")
#Rtools
# Instalação do pacote tabular
remove.packages("tabular")
setwd("Z:/CETIC.BR (repositório)/Base de conhecimento/DesenvolvimentoTabelas/tabular")
install.packages("tabular_0.0.1.8.tar.gz", repos = NULL, type = "source")
library(tabular)
# Diretório dos dicionários e tabelas
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
# Lista todos os arquivos .csv
files <- list.files(pattern = 'csv')
files
# Seleciona cada um dos parâmetros a partir da palavra chave
indicadores <- files[grepl('indicadores', files)]
agrupamentos <- files[grepl('agrupamentos', files)]
perguntas <- files[grepl('perguntas', files)]
respostas <- files[grepl('respostas', files)]
dados <- files[grepl('dados', files)]
pesquisa <- strsplit(indicadores, "_dicionario")[[1]][1]
# Processamento Tabelas
TABELAS <- tabular::Rodar(arq_indicadores = indicadores,
arq_agrupamentos = agrupamentos,
arq_perguntas = perguntas,
arq_respostas = respostas,
dados = dados)
# Exporta tabelas
TABELAS$prop <- tabular::ExportarTabela(TABELAS, type = "prop", idioma = "pt")
TABELAS$erro <- tabular::ExportarTabela(TABELAS, type = "erro", idioma = "pt")
TABELAS$total <- tabular::ExportarTabela(TABELAS, type = "total", idioma = "pt")
TABELAS$errototal <- tabular::ExportarTabela(TABELAS, type = "errototal", idioma = "pt")
# Salva tabelas no diretório
openxlsx::saveWorkbook(wb = TABELAS$prop,
file = paste0(pesquisa, "_tabela_proporcao_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$erro,
file = paste0(pesquisa, "_tabela_margem_de_erro_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$total,
file = paste0(pesquisa, "_tabela_total_v1.0.xlsx"),
overwrite = TRUE)
openxlsx::saveWorkbook(wb = TABELAS$errototal,
file = paste0(pesquisa, "_tabela_margem_de_erro_total_v1.0.xlsx"),
overwrite = TRUE)
# Verifica o scale utilizado
# Domicílios 2020: scale=0.00642244440548866
# Indivíduos 2020: scale=0.00686237914069572
# Ondas Painel: scale=0.00684006541327602
# Painel Onda 5: scale=0.00684008296372294
# Cultura 2022: scale =0.00545711704814438
# Saúde 2022 Gestores: scale =0.0079664308705664
# Saúde 2022 Médicos: scale =0.0100030602022529
# Saúde 2022 Enfermeiros: scale =0.00879658739063795
# Painel Onda 6: scale = 0.00562035721138633
TABELAS$design$scale
TABELAS$design$combined.weights
TABELAS$design$type
